package mos

import (
	"encoding/xml"
	"sync"

	"github.com/bububa/opentaobao/model"
)

// AlibabaMjOcPayAPIResponse POS收银成功后订单同步 API返回值
// alibaba.mj.oc.pay
//
// 此API用于在银泰商场中，消费者在收银台收银/退款时， POS系统在收银或退款成功后，调用此接口进行订单同步
type AlibabaMjOcPayAPIResponse struct {
	model.CommonResponse
	AlibabaMjOcPayAPIResponseModel
}

// Reset 清空结构体
func (m *AlibabaMjOcPayAPIResponse) Reset() {
	(&m.CommonResponse).Reset()
	(&m.AlibabaMjOcPayAPIResponseModel).Reset()
}

// AlibabaMjOcPayAPIResponseModel is POS收银成功后订单同步 成功返回结果
type AlibabaMjOcPayAPIResponseModel struct {
	XMLName xml.Name `xml:"alibaba_mj_oc_pay_response"`
	// 平台颁发的每次请求访问的唯一标识
	RequestId string `json:"request_id,omitempty" xml:"request_id,omitempty"`
	// POS交易号
	OutTradeNo string `json:"out_trade_no,omitempty" xml:"out_trade_no,omitempty"`
	// errMsg
	ExMsg string `json:"ex_msg,omitempty" xml:"ex_msg,omitempty"`
	// errCode
	ExCode int64 `json:"ex_code,omitempty" xml:"ex_code,omitempty"`
	// success
	IsSuccess bool `json:"is_success,omitempty" xml:"is_success,omitempty"`
}

// Reset 清空结构体
func (m *AlibabaMjOcPayAPIResponseModel) Reset() {
	m.RequestId = ""
	m.OutTradeNo = ""
	m.ExMsg = ""
	m.ExCode = 0
	m.IsSuccess = false
}

var poolAlibabaMjOcPayAPIResponse = sync.Pool{
	New: func() any {
		return new(AlibabaMjOcPayAPIResponse)
	},
}

// GetAlibabaMjOcPayAPIResponse 从 sync.Pool 获取 AlibabaMjOcPayAPIResponse
func GetAlibabaMjOcPayAPIResponse() *AlibabaMjOcPayAPIResponse {
	return poolAlibabaMjOcPayAPIResponse.Get().(*AlibabaMjOcPayAPIResponse)
}

// ReleaseAlibabaMjOcPayAPIResponse 将 AlibabaMjOcPayAPIResponse 保存到 sync.Pool
func ReleaseAlibabaMjOcPayAPIResponse(v *AlibabaMjOcPayAPIResponse) {
	v.Reset()
	poolAlibabaMjOcPayAPIResponse.Put(v)
}
